import 'package:flutter/material.dart';
import 'package:kasax_demos2/meiyingfilm/entry/appconst.dart';
import 'package:kasax_demos2/meiyingfilm/page_newhomelist.dart';

import 'drawer_home.dart';
import 'page_homelist.dart';

/// Flutter 下拉刷新上拉加载（电影app客户端案例）
/// https://www.jianshu.com/p/de0201e5aeb9
///
///豆瓣电影的API接口
/// https://www.jianshu.com/p/6e48425d2c63
/// 黑马API： http://www.liulongbin.top:3005/api/getlunbo
class MeiyFilmDemo extends StatefulWidget {
  const MeiyFilmDemo({Key? key}) : super(key: key);

  @override
  _MeiyFilmDemoState createState() => _MeiyFilmDemoState();
}

class _MeiyFilmDemoState extends State<MeiyFilmDemo> {
  List<Widget> pages = [];

  // List<Widget> pages = [
  //   NewMovieListPage(Configs.PAGE_FLAGS[0]),
  //   NewMovieListPage(Configs.PAGE_FLAGS[1]),
  //   NewMovieListPage(Configs.PAGE_FLAGS[2])
  // ];

  int _currentPage = 0;

  List<Tab> _tabs = [
    Tab(
      iconMargin: EdgeInsets.zero,
      icon: Icon(Icons.view_agenda),
      text: "正在热映",
    ),
    Tab(
      iconMargin: EdgeInsets.zero,
      icon: Icon(Icons.face_retouching_natural),
      text: "即将上映",
    ),
    Tab(
      iconMargin: EdgeInsets.zero,
      icon: Icon(Icons.local_convenience_store),
      text: "Top250",
    )
  ];

  @override
  void initState() {
    pages = List.generate(
        3, (index) => NewMovieListPage(Configs.PAGE_FLAGS[index]));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 3,
        child: MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData(primaryColor: Colors.blue),
          home: Scaffold(
            appBar: AppBar(
              elevation: 0,
              title: Text(
                "魅影",
                style: TextStyle(fontSize: 16, color: Colors.white),
              ),
              centerTitle: true,
            ),
            drawer: MovieDrawerHome(),
            body: IndexedStack(
              index: _currentPage,
              children: pages,
            ),
            bottomNavigationBar: Container(
              height: 55,
              color: Colors.blue,
              child: TabBar(
                labelStyle: TextStyle(fontSize: 12.0),
                labelColor: Colors.lightBlueAccent,
                unselectedLabelColor: Colors.white,
                onTap: (index) {
                  setState(() {
                    _currentPage = index;
                  });
                },
                tabs: _tabs,
              ),
            ),
          ),
        ));
  }
}
